package cn.shengongying.service.impl;

import cn.shengongying.exception.BusinessException;
import cn.shengongying.model.BossOrder;
import cn.shengongying.model.PayResult;
import cn.shengongying.service.IPayStrategyService;

import java.util.Map;

/**
 * author: RXK
 * date: 2022/1/10 星期一
 * desc:
 */
public abstract class AbstractPayStrategyServiceService implements IPayStrategyService {


    @Override
    public PayResult pay(BossOrder bossOrder) throws Exception {
        Map<String, String> prepayParams = prepayParams(bossOrder);
        Map<String, String> result = prepay(prepayParams);
        return prepayResult(result,bossOrder);
    }

    @Override
    public void callback(Map<String, String> callback) {
        handleCallback(callback);
    }

    @Override
    public void refund(BossOrder bossOrder) {
        orderRefund(bossOrder);
    }

    @Override
    public void handleRefundCallback(Map<String, String> data) {
        handleRefund(data);
    }

    protected abstract void handleRefund(Map<String, String> data);

    protected abstract void orderRefund(BossOrder bossOrder);

    protected abstract void handleCallback(Map<String, String> callback);


    protected abstract Map<String, String> prepayParams(BossOrder bossOrder) throws BusinessException;

    protected abstract Map<String, String> prepay(Map<String, String> prepayParams) throws Exception;

    protected abstract PayResult prepayResult(Map<String, String> prepay, BossOrder bossOrder) throws Exception;
}
